﻿package view.popup
{
    import cmd.*;
    import com.core.*;
    import com.sh.game.global.*;
    import flash.events.*;
    import flash.utils.*;
    import manager.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import plugin.instance.*;
    import plugin.instances.*;
    import plugin.union.*;
    import uiresource.*;
    import view.mornExtends.*;

    public class ActivePopUp extends ActivetsUI implements IDialogUI
    {
        public var curdata:Object;
        private var _timeID:uint = 0;

        public function ActivePopUp()
        {
            return;
        }// end function

        override protected function initialize() : void
        {
            super.initialize();
            this.btnClose.clickHandler = new Handler(this.close);
            this.btn_qianwang.clickHandler = new Handler(this.goHandler);
            GlobalLayer.instance.root.addEventListener(Event.RESIZE, this.resizeHandler);
            this.x = GlobalLayer.instance.root.stage.stageWidth - this.width - 50;
            this.y = GlobalLayer.instance.root.stage.stageHeight - this.height - 100;
            return;
        }// end function

        protected function resizeHandler(event:Event) : void
        {
            this.x = GlobalLayer.instance.root.stage.stageWidth - this.width - 50;
            this.y = GlobalLayer.instance.root.stage.stageHeight - this.height - 100;
            return;
        }// end function

        private function goHandler() : void
        {
            if (this.curdata == null)
            {
                return;
            }
            var _loc_1:Array = [];
            if (this.curdata.mapid > 0)
            {
                PluginManager.instance.sendToServer("instance", CMDInstance.HuoDongApp, this.curdata.mapid);
            }
            else
            {
                _loc_1 = this.curdata.npcid.split("#");
                if (_loc_1[0] > 0)
                {
                    ModelProxy.change("data", "taskfindpath", _loc_1[0]);
                }
                ModelProxy.change("zone", "stopGuaji", null);
                if (this.curdata.transtype == 1)
                {
                    PluginManager.instance.sendToServer("activity", CMDActivity.Trans, {x:_loc_1[1], y:_loc_1[2], tostageid:_loc_1[3], free:1});
                }
                ModelProxy.change("zone", "autoMove", {x:_loc_1[1], y:_loc_1[2], tostageid:_loc_1[3], onhorse:true});
            }
            this.close();
            return;
        }// end function

        public function close() : void
        {
            if (this._timeID > 0)
            {
                clearTimeout(this._timeID);
                this._timeID = 0;
            }
            this.visible = false;
            return;
        }// end function

        public function show(param1:Object) : void
        {
            var _loc_9:String = null;
            var _loc_10:Array = null;
            var _loc_11:int = 0;
            var _loc_12:int = 0;
            var _loc_13:Object = null;
            var _loc_15:int = 0;
            var _loc_16:Object = null;
            var _loc_17:Object = null;
            var _loc_18:int = 0;
            var _loc_19:Object = null;
            var _loc_20:Object = null;
            var _loc_21:ItemSplit = null;
            var _loc_22:Array = null;
            var _loc_2:Boolean = false;
            this.curdata = param1[0];
            if (this.curdata)
            {
                if (this.curdata.hasOwnProperty("showpop"))
                {
                    if (this.curdata.showpop == 1)
                    {
                        _loc_2 = true;
                    }
                }
            }
            if (!_loc_2)
            {
                this.visible = false;
                return;
            }
            if (this.curdata.dietype == 3)
            {
                _loc_15 = UserData.getUserData("unionid");
                if (_loc_15 == 0)
                {
                    this.visible = false;
                    return;
                }
                _loc_16 = ModelProxy.getValue("data", "unionEmsState");
                if (_loc_16 == null)
                {
                    this.visible = false;
                    return;
                }
                if (_loc_16.num == 2)
                {
                    this.visible = false;
                    return;
                }
                if (_loc_16.state != 1)
                {
                    _loc_17 = ModelProxy.getValue("data", "unionInfo");
                    if (_loc_17)
                    {
                        _loc_18 = UserData.getUserData("rid");
                        for each (_loc_20 in _loc_17.memberList)
                        {
                            
                            if (_loc_18 == _loc_20.rid)
                            {
                                _loc_19 = _loc_20;
                                break;
                            }
                        }
                        if (_loc_19 != null)
                        {
                            if (_loc_19.title < 10)
                            {
                                this.visible = false;
                                return;
                            }
                        }
                        else
                        {
                            this.visible = false;
                            return;
                        }
                    }
                    else
                    {
                        ModelProxy.change("data", "unionEmsPopWait", true);
                        UnionSender._4getUnionInfo(_loc_15);
                        this.visible = false;
                        return;
                    }
                }
            }
            this.visible = true;
            var _loc_3:Array = [];
            var _loc_4:* = this.curdata.info;
            this.labelTitle.text = this.curdata.name;
            labelDesc.text = "<font color=\"#ffcc00\">" + "活动规则:" + "</font><font color=\"#b29a6c\">" + _loc_4 + "</font>";
            var _loc_5:* = this.curdata.time;
            var _loc_6:* = this.curdata.time.split("-");
            var _loc_7:* = (this.curdata.time.split("-")[0] as String).split("#");
            var _loc_8:* = (_loc_6[1] as String).split("#");
            var _loc_14:* = ConfigDictionary.data.item;
            if (this.curdata.type == 1)
            {
                _loc_9 = this.curdata.items;
                if (_loc_9)
                {
                    _loc_10 = _loc_9.split("#");
                    _loc_11 = 0;
                    _loc_12 = 0;
                    while (_loc_12 < _loc_10.length)
                    {
                        
                        _loc_13 = _loc_14[_loc_10[_loc_12]];
                        if (_loc_13 == null)
                        {
                        }
                        else
                        {
                            _loc_3.push(_loc_13);
                            _loc_11++;
                        }
                        _loc_12++;
                    }
                    list.array = _loc_3;
                    list.renderHandler = new Handler(this.goodsRender);
                }
            }
            else if (this.curdata.rews)
            {
                _loc_9 = this.curdata.rews;
                if (_loc_9)
                {
                    _loc_21 = new ItemSplit();
                    _loc_22 = _loc_21.doSplits(_loc_9, "&", "/", "#");
                    _loc_10 = _loc_22[0];
                    _loc_11 = 0;
                    _loc_12 = 0;
                    while (_loc_12 < _loc_10.length)
                    {
                        
                        _loc_13 = _loc_14[_loc_10[_loc_12]];
                        if (_loc_13 == null)
                        {
                        }
                        else
                        {
                            _loc_3.push(_loc_13);
                            _loc_11++;
                        }
                        _loc_12++;
                    }
                    list.array = _loc_3;
                    list.renderHandler = new Handler(this.goodsRender);
                }
            }
            if (_loc_3.length > 0)
            {
                this.rewbox.visible = true;
            }
            else
            {
                this.rewbox.visible = false;
            }
            this._timeID = setTimeout(this.close, 300000);
            return;
        }// end function

        private function goodsRender(param1:Component, param2:int) : void
        {
            if (param2 < list.length)
            {
                (param1 as FlashItem).data = list.array[param2];
            }
            return;
        }// end function

    }
}
